const Router = require('koa-router')
const clientService = require('../services/client')
const router = new Router({prefix:'/api/client'})

// const middle = () => {
//     // ctx.set('Accept','application/json')
//     console.log('col')
// }

// 访问主页获取数据
router.get('/view/:username', async (ctx)=>{
    console.log('col,view')
    let {username} = ctx.params
    const list = await clientService.clientView(username)
    // ctx.send({list:list,res:200})
    console.log(list)
    if(list){
        ctx.body = {list:list,code:200}
    }else{
        ctx.body = {msg:'没有该用户',code:201}
    }
    
    //  next()
})

// 注册
router.post('/register',async (ctx)=>{
    const {username,password} = ctx.request.body
    // console.log(ctx)
    // ?
    let result = await clientService.clientRegister(username,password)
    // if(result == 200){
    //     ctx.body = {}
    // }else{
        console.log(result)
        ctx.body = {}
    // }

})

// 登陆
router.post('/login',async (ctx)=>{
    console.log('')
    const {username,password} = ctx.request.body
    // ?
    await clientService.clientLogin(username,password)
    // if(result == 200){
    //     ctx.body = {}
    // }else{
    //     ctx.body = {}
    // }
    ctx.body = {}
})

module.exports = router